<script setup lang="ts">
import { ref } from 'vue'
import Header from '@/components/Headerlist.vue'
import MainSection from '@/components/Mainlist.vue'
import Footer from '@/components/Footer.vue'
import type { TodoItem } from '@/components/types'

const list = ref<TodoItem[]>([])

const handleAddTodo = (todo: TodoItem) => {
  list.value.push(todo)
}

const handleDeleteTodo = (id: number) => {
  list.value = list.value.filter(item => item.id !== id)
}

const handleClearList = () => {
  list.value = []
}
</script>

<template>
  <div class="title">
    <h1 style="font-size: 30px; color:red"><a href="#">仓库地址</a></h1>
  </div>
  <section id="app">
    <Header 
      :list-length="list.length" 
      @add-todo="handleAddTodo" 
    />
    <MainSection 
      :list="list" 
      @delete-todo="handleDeleteTodo" 
    />
    <Footer 
      :list-length="list.length" 
      @clear-list="handleClearList" 
    />
  </section>
</template>
<style>
body {
  font-family: 'Arial', sans-serif;
  background-color: #f9f9f9;
  margin: 0;
  padding: 0;
  color: #333;
}

#app {
  max-width: 500px;
  margin: 20px auto;
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  font-size: 24px;
  color: #333;
  margin: 0;
}

.new-todo {
  width: 70%;
  padding: 8px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-right: 10px;
}

.add {
  padding: 8px 16px;
  font-size: 14px;
  background-color: #007bff;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.add:hover {
  background-color: #0056b3;
}

.todo-list {
  list-style: none;
  padding: 0;
}

.todo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #eee;
}

.todo:last-child {
  border-bottom: none;
}

.todo .index {
  color: #888;
  margin-right: 10px;
}

.todo label {
  flex: 1;
  font-size: 16px;
}

.todo .destroy {
  background: none;
  border: none;
  color: #ff4c4c;
  font-size: 16px;
  cursor: pointer;
}

.todo .destroy:hover {
  color: #cc0000;
}

/* 底部样式 */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid #eee;
}

.todo-count {
  font-size: 14px;
  color: #888;
}

.clear-completed {
  background: none;
  border: none;
  color: #007bff;
  font-size: 14px;
  cursor: pointer;
}

.clear-completed:hover {
  color: #0056b3;
}
</style>
